package lime.xquery.view;

import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.part.ViewPart;

public class XQueryEditorView extends ViewPart {

	public static final String ID = "lime.xquery.view.editor";
	
	private Text xqueryText;

	@Override
	public void createPartControl(Composite parent) {
		
		xqueryText = new Text(parent, SWT.WRAP | SWT.MULTI | SWT.V_SCROLL);
		xqueryText.setFont(JFaceResources.getTextFont());
		
		xqueryText.addModifyListener(new ModifyListener() {
			@Override
			public void modifyText(ModifyEvent event) {
				IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage();
				XQueryParametersView view = (XQueryParametersView) page.findView(XQueryParametersView.ID);
				view.update(xqueryText.getText());
			}
		});

	}

	@Override
	public void setFocus() {
		xqueryText.setFocus();
	}
	
	public String getXQueryString() {
		return xqueryText.getText();
	}

}
